<!--  Nguyen Huu Nhat -->
<?php 
@session_start();
include '../Security/CheckAdmin.php';
include '../Home/DefineVar.php';
include '../DataBase/ConnectDB.php';

mysql_select_db(MYSQL_DATABASE, $link) 
	or exit('Could not select database'.mysql_error());
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
////////////////////////////////////////////////////////////////////////
$roomName = mysql_real_escape_string($_POST['roomName']);
$chairNumber = mysql_real_escape_string($_POST['chairNumber']);
$useFee = mysql_real_escape_string($_POST['useFee']);
$cancelFee = mysql_real_escape_string($_POST['cancelFee']);
$fineFee =mysql_real_escape_string($_POST['fineFee']);
$orderFee =mysql_real_escape_string($_POST['orderFee']);
$cancelFeeAll = mysql_real_escape_string($_POST['cancelFeeAll']);
$orderFeeAll = mysql_real_escape_string($_POST['orderFeeAll']);
$fineFeeAll = mysql_real_escape_string($_POST['fineFeeAll']);
$roomId = mysql_real_escape_string($_POST['roomId']);
$roomUpdate = mysql_real_escape_string($_POST['delete']);
$roomStatus=mysql_real_escape_string($_POST['roomStatus']);
//会議室の削除
if($roomUpdate == "削除"){
	$query = "DELETE FROM ".MYSQL_TABLE_ROOMINFOR." WHERE roomid='$roomId';";
       $result = mysql_query($query, $link);
        if(!$result){
     		print("<br><script type='text/javascript'> alert('".DEL_ROOM_ERR_MESS."'); window.location ='SearchRoom.php';</script> ");
   			exit();
        }
        else{
         	print("<br><script type='text/javascript'> alert('".DEL_ROOM_OK_MESS."'); window.location ='SearchRoom.php';</script> ");
     		exit();
        }
}
  
        $query = "UPDATE ".MYSQL_TABLE_ROOMINFOR." 
        			SET roomname = '$roomName', seatnumber = '$chairNumber', usingcost = '$useFee', fineFee = '$fineFee', cancelfee = '$cancelFee', orderfee ='$orderFee', roomstatus ='$roomStatus' 
        			WHERE roomid ='$roomId'";
        //print($query);
        if(($result = mysql_query($query, $link))){
 			print("<br><script type='text/javascript'> alert('".UPDATE_ROOM_OK_MESS."'); window.location ='SearchRoom.php';</script> ");
        }
        else{
               print("<br><script type='text/javascript'> alert('".UPDATE_ROOM_ERR_MESS."'); window.location ='SearchRoom.php';</script> ");
               exit();
        }
        if($cancelFeeAll){
        	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET cancelfee ='".$cancelFee."';",$link);
        }
        if($orderFeeAll){
        	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET orderfee ='".$orderFee."';",$link);
        }
         if($fineFeeAll){
        	mysql_query("UPDATE ".MYSQL_TABLE_ROOMINFOR." SET finefee ='".$fineFee."';",$link);
        }
 mysql_close($link);
?>
</body>
</html>